<?php
//1、设置编码utf8
header("Content-Type: text/html; charset=UTF-8");



require("conn.php");

 

$image= $_FILES['pic'];


$up = upimgs($image);

 function upimgs($img){


 if ($img!='') {
$img2 = $img;
 }

$tp = array("image/pjpeg","image/jpeg","image/png"); 

$shifou='';
for ($i2=0; $i2 <count($tp); $i2++) { 
 if ($tp[$i2]==$img2 ['type']) {
   $shifou=1;
 }
}

if ($shifou!=1) {
 echo "no";
 return false;
}
//随机文件名
$name1 =time();
$base = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$count = strlen($base);
$random = '';
for ($i3=0; $i3 < 16; $i3++) { 
 $random.=$base[rand(0,$count-1)];
}

//图片类型获取
$houzui = get_file_type($img2['name']);
$name2 = $name1.$random.".".$houzui;
$name2 = "upload/".$name2;

//7、移动临时文件到上传的文件存放位置（核心代码）
copy($img2['tmp_name'], $name2);


 if (file_exists($name2)=='ture'){
echo $name2;

 }else{
  echo "'no";
 }



}






//**********************************************
function base64EncodeImage ($image_file) {

$base64_image = '';

$image_info = getimagesize($image_file);

$image_data = fread(fopen($image_file, 'r'), filesize($image_file));

$base64_image = 'data:' . $image_info['mime'] . ';base64,' . chunk_split(base64_encode($image_data));

return $base64_image;

}
//**********************************************

function get_file_type($filename)
{  
   $type =explode("." , $filename);
   $count=count($type)-1;
   return $type[$count];
}
